<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>MuYuCMS-后台登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="MuYu content management system is a continuous forward excellent background management system.">
    {load href="__ADMINST__layuiadmin/layui/css/layui.css"}
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    {load href="__ADMINST__muyuadmin/css/muyulogin.css"}
</head>
<body>
<div class="main-body">
    <div class="login-main">
        <div class="login-top">
            <span>MuYuCMS后台登录</span>
            <span class="bg1"></span>
            <span class="bg2"></span>
        </div>
        <form class="layui-form login-bottom">
            <div class="center">
                <div class="item">
                    <span class="icon icon-2"></span>
                    <input type="text" id="adminName" name="name" lay-verify="required" value="{$Think.session.adname}"  placeholder="请输入登录账号" maxlength="24"/>
                </div>

                <div class="item">
                    <span class="icon icon-3"></span>
                    <input type="password" id="password" name="password" lay-verify="required"  placeholder="请输入密码" maxlength="20">
                    <span class="bind-password icon icon-4"></span>
                </div>
                {if !empty($Think.session.pwderror)}
                <div id="validatePanel" class="item" style="width: 137px;">
                    <input type="text" id="captcha" name="verif" placeholder="请输入验证码" maxlength="4">
                    <img id="refreshCaptcha" class="validateImg"  src="{:captcha_src()}" onClick="this.src=this.src+'?'+Math.random()" >
                </div>
                {/if}
            </div>
            <div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;">
                <input type="button" class="login-btn" id="submit" value="立即登录" />
            </div>
        </form>
    </div>
</div>
<div class="footer">
    2020-<?php echo date('Y');?> 木鱼内容管理系统 All Rights Reserved.
</div>
{load href="__ADMINST__layuiadmin/layui/layui.js"}
<script type="text/javascript" src="__ADMINLIB__jquery/1.9.1/jquery.min.js"></script>
<script>
    layui.use(['form','jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

        $('.bind-password').on('click', function () {
            if ($(this).hasClass('icon-5')) {
                $(this).removeClass('icon-5');
                $("input[name='password']").attr('type', 'password');
            } else {
                $(this).addClass('icon-5');
                $("input[name='password']").attr('type', 'text');
            }
        });

        $('.icon-nocheck').on('click', function () {
            if ($(this).hasClass('icon-check')) {
                $(this).removeClass('icon-check');
            } else {
                $(this).addClass('icon-check');
            }
        });
    });
    //回车登录
    $(document).keyup(function(e) {
        if (e.keyCode === 13) {
            login();
        }
    });
    $(function () {
        // 登陆事件
        $('#submit').click(function () {
            login();
        });
    });
    function login(){
        var name = $("#adminName").val();
        var pwd = $("#password").val();
        var ver = $("#captcha").val();

        if(name == ""){
            layer.msg('账号为空!',{icon:2,time:2000},function(){
                $("#adminName").focus();
            });
        }else{
            if(pwd == ""){
                layer.msg('密码为空!',{icon:2,time:2000},function(){
                    $("#password").focus();
                });
            }else{
                if(ver == ""){
                    layer.msg('验证码为空!',{icon:2,time:2000},function(){
                        $("#captcha").focus();
                    });
                }else{
                    layer.msg('正在登录…', { icon: 16, shade: 0.21,shadeClose:true,time:2000 },function(){
                        $.ajax({
                            type:"POST",
                            data:{adminName:name,
                                password:pwd,
                                captcha:ver
                            },
                            dataType:'json',
                            url:"{:url('admin/Login/login')}",
                            success:function(data){
                                if(data.code == 0){
                                    layer.msg(data.msg,{icon:2,time:2000},function(){
                                        location.reload();
                                        //document.getElementById("verif_img").onclick();
                                    });
                                }else{
                                    layer.msg(data.msg,{icon:6,time:2000},function(){
                                        if(data.url != ""){
                                            location.href = data.url;
                                        }
                                    });
                                }
                            }
                        });
                    });
                }
            }
        }
    }
</script>
</body>
</html>